package initialize

import (
	"cron_table_admin/global"
	"cron_table_admin/internal/router"
	"cron_table_admin/middleware"

	"github.com/gin-gonic/gin"
)

func Routers() *gin.Engine {
	GinMode := global.SERVER_CONFIG.System.GinMode
	gin.SetMode(GinMode)
	Router := gin.New()
	Router.Use(middleware.CORSMiddleware())

	// 跨域
	//Router.Use(middleware.Cors(), middleware.LoadTls(), middleware.ParseParamMiddleware(), middleware.
	//	GinRecovery(true))
	global.LOGGER.Debug("use common middleware success")

	// 生产环境不配置swag， 初始化swag
	//if GinMode != gin.ReleaseMode {
	//	Router.GET("/docs/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	//	global.LOGGER.Debug("register swagger handler")
	//}

	// 方便统一添加路由组前缀 多服务器上线使用
	ApiGroup := Router.Group("/api")
	ApiGroup.Use(middleware.ApiLogMiddleware())

	router.InitUserRouter(ApiGroup)
	router.InitCronRouter(ApiGroup)

	global.LOGGER.Debug("router register success")

	return Router
}
